preventing changes to a cell in google spreadsheet [migrated]

Posted by A B on Programmers See other posts from Programmers or by A B
Published on 2012-11-12T21:31:55Z Indexed on 2012/11/12 23:13 UTC
Read the original article Hit count: 100

Filed under:

I want to prevent changes to column K in google spreadsheet. Whatever value is there, I do not want it changed. I do not like the protection feature as it makes what I consider an ugly display.

My code. Unfortunately, it does absolutely nothing. The intent was to take whatever the current value is in the cell, save it, and then write it back on exit of the cell instead of saving whatever changes might have been made to the cell. The cell will either be blank to start, or will already have been modified to contain a date & time. Whatever the current contents blank or not, it should retain the same value after leaving the cell.

function onEdit() {
  var s = SpreadsheetApp.getActiveSheet();
  var r = s.getActiveCell();
  var columnNum=r.getColumn() 


  // if column is K then prevent any changes
  if (columnNum == 11) {
    var dateCell = s.getRange(r.getRow(), 11);
    var v=dateCell.getValue();
    dateCell.setValue(v);
  }
};

© Programmers or respective owner

Related posts about spreadsheet